<!--银行卡管理-->
<template xmlns="">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="国家中文" prop="chineseName">
        <el-input v-model="queryParams.chineseName" placeholder="请输入国家中文" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="国家英文" prop="englishName">
        <el-input v-model="queryParams.englishName" placeholder="请输入国家英文" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="国家简写" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入国家简写" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="国家中文" align="center" prop="chineseName" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="国家英文" align="center" prop="englishName" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="国家简写" align="center" prop="code" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="币种" align="center" prop="currency" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="国家电话号码前缀" align="center" prop="phoneAreaNumber" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="汇率" align="center" prop="exchangeRate" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
            <div>{{scope.row.exchangeRate}}</div>
            <div style="color: #c0c4cc;font-size: 12px">（1美元兑换{{scope.row.exchangeRate}}）</div>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180"
                       :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{m}/{d}/{y}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <div>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />
    <!-- 添加或修改 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item label="汇率" prop="exchangeRate">
          <el-input-number :controls="true" :min="0" class="modal-input" v-model="form.exchangeRate"
                           placeholder="请输入汇率" />
        </el-form-item>
        <el-form-item label="币种" prop="currency">
          <el-input-number :controls="true" :min="0" class="modal-input" v-model="form.currency"
                           placeholder="请输入币种" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { manageList, deleteManageData, manageDataDetails, addManageData ,updateState} from '@/api/bank/bankCard'
import OssImagePreview from '@/components/ImagePreview/oss-image-preview.vue'
import { countryEdit, countryList } from '@/api/setting/nation'
import Template from '@/views/setting/template/index.vue'

export default {
  name: 'bankCardManage',
  components: { Template, OssImagePreview },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 用户完成线下理财信息表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseName:null,
        englishName:null,
        code:null,
      },
      open: false,
      title: '',
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        exchangeRate:{required: true, message: '汇率不能为空', trigger: 'blur'},
        currency:{required: true, message: '币种不能为空', trigger: 'blur'}
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      countryList(this.queryParams).then(response => {
        this.dataList = response.data.records
        this.dataList.forEach(item => {
          if(item.exchangeRate == null) item.exchangeRate = 0;
          item.exchangeRate = item.exchangeRate.toFixed(4)
        })
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      this.form = JSON.parse(JSON.stringify(row))
      this.open = true
      this.title = '修改汇率'

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          countryEdit(this.form).then(response => {
            this.$modal.msgSuccess('新增成功')
            this.open = false
            this.getList()
          })
        }
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        bankName: null,
        bankIcon: null
      }
      this.resetForm('form')
    },
  }
}
</script>
